package com.bq.gametrade.ui.dialog;

import android.content.ClipboardManager;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.utils.ToastUtils;

/**
 * Created by Feel on 2016/12/23.
 */

public class CustomerServiceDialog extends DialogFragment {

    private Button btnCopy, btnCall;

    private ClipboardManager clipboardManager;

    private TextView tvPhoneNo,tvWXAccount;

    private String wxAccount = "gxfc17988";
    private String phoneNo = "13533575429";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        clipboardManager =  (ClipboardManager)getActivity().getSystemService(getActivity().CLIPBOARD_SERVICE);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.dialog_customeservice, container);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        Window window = getDialog().getWindow();

        WindowManager.LayoutParams lp = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setAttributes(lp);
        getDialog().show();
        initView(view);
        return view;

    }

    private void initView(View view) {
        tvWXAccount = (TextView) view.findViewById(R.id.tv_wxAccount);
        tvWXAccount.setText(wxAccount);
        tvPhoneNo = (TextView) view.findViewById(R.id.tv_phoneNo);
        tvPhoneNo.setText(phoneNo);
        btnCopy = (Button) view.findViewById(R.id.btn_copy);
        btnCopy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clipboardManager.setText(wxAccount);
                ToastUtils.showToast(getActivity(),"已复制微信号："+wxAccount+" 到粘贴板");
                dismiss();
            }
        });
        btnCall = (Button) view.findViewById(R.id.btn_call);
        btnCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNo));
                phoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //启动
                startActivity(phoneIntent);
                dismiss();

            }
        });
    }
}
